<?php

function retStrInfo($code)
{
	$lan = request()->header('local') ? request()->header('local') : 'cn';
	$language = langTip($code);
	return $language[$lan];
}

function langTip($code)
{
	switch ($code) {
		case 1:
			$language['cn'] = '该邀请码不可用';
			break;
		case 2:
			$language['cn'] = '请输入昵称';
			break;
		case 3:
			$language['cn'] = '该昵称已存在';
			break;
		case 4:
			$language['cn'] = '手机格式输入有误';
			break;
		case 5:
			$language['cn'] = '邮箱格式输入有误';
			break;
		case 6:
			$language['cn'] = '该账户已存在';
			break;
		case 7:
			$language['cn'] = '请输入6位数字的验证码';
			break;
		case 8:
			$language['cn'] = '验证码输入有误';
			break;
		case 9:
			$language['cn'] = '请输入密码';
			break;
		case 10:
			$language['cn'] = '请输入6位数字的支付密码';
			break;
		case 11:
			$language['cn'] = '注册成功';
			break;
		case 12:
			$language['cn'] = '注册失败';
			break;
		case 13:
			$language['cn'] = '该账户不存在';
			break;
		case 14:
			$language['cn'] = '密码输入有误';
			break;
		case 15:
			$language['cn'] = '该账户已冻结';
			break;
		case 16:
			$language['cn'] = '请输入确认密码';
			break;
		case 17:
			$language['cn'] = '更改成功';
			break;
		case 18:
			$language['cn'] = '更改失败';
			break;
		case 19:
			$language['cn'] = '图片格式不支持';
			break;
		case 20:
			$language['cn'] = '头像更改失败';
			break;
		case 21:
			$language['cn'] = '头像更改成功';
			break;
		case 22:
			$language['cn'] = '图片上传失败';
			break;
		case 23:
			$language['cn'] = '请选择要上传的图片';
			break;
		case 24:
			$language['cn'] = '编辑成功';
			break;
		case 25:
			$language['cn'] = '编辑失败';
			break;
		case 26:
			$language['cn'] = '请输入手机号';
			break;
		case 27:
			$language['cn'] = '请输入邮箱';
			break;
		case 28:
			$language['cn'] = '该手机号已注册';
			break;
		case 29:
			$language['cn'] = '该邮箱已注册';
			break;
		case 30:
			$language['cn'] = '发送成功';
			break;
		case 31:
			$language['cn'] = '发送失败';
			break;
		case 32:
			$language['cn'] = '手机号绑定成功';
			break;
		case 33:
			$language['cn'] = '手机号绑定失败';
			break;
		case 34:
			$language['cn'] = '邮箱绑定成功';
			break;
		case 35:
			$language['cn'] = '邮箱绑定失败';
			break;
		case 36:
			$language['cn'] = '请输入要更改的密码';
			break;
		case 37:
			$language['cn'] = '请输入6位数字的密码';
			break;
		case 38:
			$language['cn'] = '请上传身份证正面';
			break;
		case 39:
			$language['cn'] = '请上传身份证反面';
			break;
		case 40:
			$language['cn'] = '请上传手持身份证正面';
			break;
		case 41:
			$language['cn'] = '请上传手持身份证反面';
			break;
		case 42:
			$language['cn'] = '身份证正面上传失败';
			break;
		case 43:
			$language['cn'] = '身份证反面上传失败';
			break;
		case 44:
			$language['cn'] = '手持身份证正面上传失败';
			break;
		case 45:
			$language['cn'] = '手持身份证反面上传失败';
			break;
		case 46:
			$language['cn'] = '请输入真实姓名';
			break;
		case 47:
			$language['cn'] = '请输入身份证号';
			break;
		case 48:
			$language['cn'] = '提交成功,等待后台审核';
			break;
		case 49:
			$language['cn'] = '提交失败';
			break;
		case 50:
			$language['cn'] = '请填写2~6位的真实姓名';
			break;
		case 51:
			$language['cn'] = '请填写正确格式的身份证号';
			break;
		case 52:
			$language['cn'] = '仓库暂未开通';
			break;
		case 53:
			$language['cn'] = '云仓库当前已被冻结,请联系管理员开通';
			break;
		case 54:
			$language['cn'] = '该用户暂无资产';
			break;
		case 55:
			$language['cn'] = '请输入转账金额';
			break;
		case 56:
			$language['cn'] = '支付密码有误';
			break;
		case 57:
			$language['cn'] = '现金可用余额不足';
			break;
		case 58:
			$language['cn'] = '转账成功';
			break;
		case 59:
			$language['cn'] = '转账失败';
			break;
		case 60:
			$language['cn'] = '请输入客户姓名';
			break;
		case 61:
			$language['cn'] = '请输入客户联系电话';
			break;
		case 62:
			$language['cn'] = '请输入收货人';
			break;
		case 63:
			$language['cn'] = '请输入收货人联系电话';
			break;
		case 64:
			$language['cn'] = '请输入收货地址所在省份';
			break;
		case 65:
			$language['cn'] = '请输入收货地址所在城市';
			break;
		case 66:
			$language['cn'] = '请输入收货地址所在地区';
			break;
		case 67:
			$language['cn'] = '请输入收货详细地址';
			break;
		case 68:
			$language['cn'] = '添加成功';
			break;
		case 69:
			$language['cn'] = '添加失败';
			break;
		case 70:
			$language['cn'] = '该手机号已存在';
			break;
		case 71:
			$language['cn'] = '该客户不存在';
			break;
		case 72:
			$language['cn'] = '已删除';
			break;
		case 73:
			$language['cn'] = '删除失败';
			break;
		case 74:
			$language['cn'] = '编辑成功';
			break;
		case 75:
			$language['cn'] = '编辑失败';
			break;
		case 76:
			$language['cn'] = '网络异常';
			break;
		case 77:
			$language['cn'] = '该地址不存在';
			break;
		case 78:
			$language['cn'] = '请输入抬头名称';
			break;
		case 79:
			$language['cn'] = '请输入公司税号';
			break;
		case 80:
			$language['cn'] = '请输入公司地址';
			break;
		case 81:
			$language['cn'] = '请输入公司电话';
			break;
		case 82:
			$language['cn'] = '请输入开户银行';
			break;
		case 83:
			$language['cn'] = '请输入开户账户';
			break;
		case 84:
			$language['cn'] = '请输入账号';
			break;
		case 85:
			$language['cn'] = '请输入提现方式';
			break;
		case 86:
			$language['cn'] = '请输入姓名';
			break;
		case 87:
			$language['cn'] = '请选择开户银行';
			break;
		case 88:
			$language['cn'] = '请输入银行卡号';
			break;
		case 89:
			$language['cn'] = '请输入开户支行';
			break;
		case 90:
			$language['cn'] = '可用现金余额不足';
			break;
		case 91:
			$language['cn'] = '请选择开通方式';
			break;
		case 92:
			$language['cn'] = '当前账户已开通云仓库,请勿重复操作';
			break;
		case 93:
			$language['cn'] = '云仓库已开通!';
			break;
		case 94:
			$language['cn'] = '云仓库开通失败';
			break;
		case 95:
			$language['cn'] = '当前尚未实名认证,不可进行此操作';
			break;
		case 96:
			$language['cn'] = '登录成功';
			break;
		case 97:
			$language['cn'] = '该用户不存在或已被冻结';
			break;
		case 98:
			$language['cn'] = '登录密码有误';
			break;
		case 99:
			$language['cn'] = '请输入搜索商品的名称';
			break;
		case 100:
			$language['cn'] = '该订单不存在';
			break;
		case 101:
			$language['cn'] = '该订单当前不可收货';
			break;
		case 102:
			$language['cn'] = '该银行信息已存在';
			break;
		case 103:
			$language['cn'] = '请选择提现方式';
			break;
		case 104:
			$language['cn'] = '请输入提现金额';
			break;
		case 105:
			$language['cn'] = '可提现金额不足';
			break;
		case 106:
			$language['cn'] = '提现方式不存在';
			break;
		case 108:
			$language['cn'] = '已提交,等待后台审核!';
			break;
		case 109:
			$language['cn'] = '提交失败';
			break;
		case 110:
			$language['cn'] = '请选择商品';
			break;
		case 111:
			$language['cn'] = '请选择规格属性';
			break;
		case 112:
			$language['cn'] = '请选择公告信息';
			break;
		case 113:
			$language['cn'] = '该公告不存在';
			break;
		case 114:
			$language['cn'] = '请输入充值金额';
			break;
		case 115:
			$language['cn'] = '未获取到第三方信息';
			break;
		case 116:
			$language['cn'] = '请输入要绑定的手机号';
			break;
		case 117:
			$language['cn'] = '请输入要绑定的邮箱号';
			break;
		case 118:
			$language['cn'] = '请提交第三方登录方式';
			break;
		case 119:
			$language['cn'] = '该支付类型已绑定';
			break;
		case 120:
			$language['cn'] = '请输入1~15位由大小写字母组成的昵称';
			break;
		case 121:
			$language['cn'] = '该用户钱包信息有误!';
			break;
        case 200:
            $language['cn'] = '该商品已下架';
            break;
        case 201:
            $language['cn'] = '操作成功';
            break;
        case 202:
            $language['cn'] = '数据错误';
            break;
        case 203:
            $language['cn'] = '购物车商品过多请先清理';
            break;
        case 204:
            $language['cn'] = '最小选择数量为1';
            break;
        case 205:
            $language['cn'] = '手机号错误';
            break;
        case 206:
            $language['cn'] = '货款余额不足';
            break;
        case 207:
            $language['cn'] = '下单成功';
            break;
        case 208:
            $language['cn'] = '仓库已到期';
            break;
        case 209:
            $language['cn'] = '该商品库存不足';
            break;
        case 210:
            $language['cn'] = '未开通云仓库或者云仓库已冻结';
            break;
		default:
			$language['cn'] = '';
			break;
	}
	return $language;
}

// 随机数生成
function getRandomString($len, $chars=null)
{
	if (is_null($chars)) {
		$chars = "ABCDEFGHIJKLMNPQRSTUVWXYZ123456789";
	}
	mt_srand(10000000*(double)microtime());
	for ($i = 0, $str = '', $lc = strlen($chars)-1; $i < $len; $i++) {
		$str .= $chars[mt_rand(0, $lc)];
	}
	return $str;
}

//上传图片
function upload($file,$paths,$type=0){
	//头像
	if (request()->hasFile($file) && request()->file($file)->isValid()) {
		$allow_types = ['png', 'jpeg', 'jpg'];

		if (!in_array(request()->file($file)->getClientOriginalExtension(), $allow_types)) {
			return ['code' => 0, 'msg' => retStrInfo(19)];
		}
		$ext = request()->file($file)->getClientOriginalExtension();

		//获取文件的绝对路径
		$path = request()->file($file)->getRealPath();

		//定义文件名
		$filename = date('Ymdhis') . '-' . rand(1000, 9999) . "." . $ext;

		//存储文件。disk里面的public。总的来说，就是调用disk模块里的public配置
		$shangchuan = Storage::disk($paths)->put($filename, file_get_contents($path));

		if (!$shangchuan) {
			if($type == 1){
				return ['code' => 0, 'msg' => retStrInfo(42)];
			}elseif($type == 2){
				return ['code' => 0, 'msg' => retStrInfo(43)];
			}elseif($type == 3){
				return ['code' => 0, 'msg' => retStrInfo(44)];
			}elseif($type == 4){
				return ['code' => 0, 'msg' => retStrInfo(45)];
			}else{
				return ['code' => 0, 'msg' => retStrInfo(22)];
			}
		} else {
			$picname =  "/upload/".$paths."/" . $filename;
			return ['code' => 1, 'msg' => '','data'=>$picname];
		}
	} else {
		if($type == 1){
			return ['code' => 0, 'msg' => retStrInfo(38)];
		}elseif($type == 2){
			return ['code' => 0, 'msg' => retStrInfo(39)];
		}elseif($type == 3){
			return ['code' => 0, 'msg' => retStrInfo(40)];
		}elseif($type == 4){
			return ['code' => 0, 'msg' => retStrInfo(41)];
		}else{
			return ['code' => 0, 'msg' => retStrInfo(23)];
		}
	}
}

//字符串首字母大写
function pinying($s0)
{
	$fchar = ord(substr($s0, 0, 1));
	
    if (($fchar >= ord("a") and $fchar <= ord("z"))or($fchar >= ord("A") and $fchar <= ord("Z"))) return strtoupper(chr($fchar));
	$s = iconv("UTF-8", "GBK", $s0);
	$str = '/^\\d+$/';
	
	if (preg_match($str, $s)) {
		return '#';
	}
    $asc = ord($s{0}) * 256 + ord($s{1})-65536;
    if ($asc >= -20319 and $asc <= -20284)return "A";
    if ($asc >= -20283 and $asc <= -19776)return "B";
    if ($asc >= -19775 and $asc <= -19219)return "C";
    if ($asc >= -19218 and $asc <= -18711)return "D";
    if ($asc >= -18710 and $asc <= -18527)return "E";
    if ($asc >= -18526 and $asc <= -18240)return "F";
    if ($asc >= -18239 and $asc <= -17923)return "G";
    if ($asc >= -17922 and $asc <= -17418)return "H";
    if ($asc >= -17417 and $asc <= -16475)return "J";
    if ($asc >= -16474 and $asc <= -16213)return "K";
    if ($asc >= -16212 and $asc <= -15641)return "L";
    if ($asc >= -15640 and $asc <= -15166)return "M";
    if ($asc >= -15165 and $asc <= -14923)return "N";
    if ($asc >= -14922 and $asc <= -14915)return "O";
    if ($asc >= -14914 and $asc <= -14631)return "P";
    if ($asc >= -14630 and $asc <= -14150)return "Q";
    if ($asc >= -14149 and $asc <= -14091)return "R";
    if ($asc >= -14090 and $asc <= -13319)return "S";
    if ($asc >= -13318 and $asc <= -12839)return "T";
    if ($asc >= -12838 and $asc <= -12557)return "W";
    if ($asc >= -12556 and $asc <= -11848)return "X";
    if ($asc >= -11847 and $asc <= -11056)return "Y";
    if ($asc >= -11055 and $asc <= -10247)return "Z";
    return '#';


	// $fchar = ord($str{0});
	// if ($fchar >= ord("A") and $fchar <= ord("z")) return strtoupper($str{0});
	// $a = $str;
	// $val = ord($a{0}) * 256 + ord($a{1}) - 65536;
	// if ($val >= -20319 and $val <= -20284) return "A";
	// if ($val >= -20283 and $val <= -19776) return "B";
	// if ($val >= -19775 and $val <= -19219) return "C";
	// if ($val >= -19218 and $val <= -18711) return "D";
	// if ($val >= -18710 and $val <= -18527) return "E";
	// if ($val >= -18526 and $val <= -18240) return "F";
	// if ($val >= -18239 and $val <= -17923) return "G";
	// if ($val >= -17922 and $val <= -17418) return "H";
	// if ($val >= -17417 and $val <= -16475) return "J";
	// if ($val >= -16474 and $val <= -16213) return "K";
	// if ($val >= -16212 and $val <= -15641) return "L";
	// if ($val >= -15640 and $val <= -15166) return "M";
	// if ($val >= -15165 and $val <= -14923) return "N";
	// if ($val >= -14922 and $val <= -14915) return "O";
	// if ($val >= -14914 and $val <= -14631) return "P";
	// if ($val >= -14630 and $val <= -14150) return "Q";
	// if ($val >= -14149 and $val <= -14091) return "R";
	// if ($val >= -14090 and $val <= -13319) return "S";
	// if ($val >= -13318 and $val <= -12839) return "T";
	// if ($val >= -12838 and $val <= -12557) return "W";
	// if ($val >= -12556 and $val <= -11848) return "X";
	// if ($val >= -11847 and $val <= -11056) return "Y";
	// if ($val >= -11055 and $val <= -10247) return "Z";
	

}

/**
 * 阿里云对象存储
 * path   路径
 * file   图片name
*/

function common_up($path,$file,$drive='oss'){
	$disk = Storage::disk($drive);
	//将图片上传到OSS中，并返回图片路径信息 值如:avatar/WsH9mBklpAQUBQB4mL.jpeg
	$path = $disk->put($path, $file);
	//由于图片不在本地，所以我们应该获取图片的完整路径，
	//值如：https://test.oss-cn-hongkong.aliyuncs.com/avatar/8GdIcz1NaCZ.jpeg
	return $disk->url($path);
}

//前补0
function zero($num){
	$num=str_pad($num,6,"0",STR_PAD_LEFT);   
	return $num;
}


